<%@ page contentType="text/html; charset=utf-8"%>
<%@ include file="../../../common/include.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>添加员工信息</title>
<jsp:include page="../../../common/head.jsp">
	  <jsp:param name="_useCalendar" value="true"/>
</jsp:include>
<script language="javascript">
	function saveData(){
		if(codeState!=true)
			return;
		var objarr = new Array(
			["empEmployee.employeeName","人员名称","notEmpty",""],
			["empEmployee.employeeName","人员名称","max","String:50"],
			["empEmployee.employeeCode","员工编号","notEmpty",""],
			["empEmployee.employeeCode","员工编号","max","String:50"],
			["empEmployee.idNumber","身份证号","cardNo","String:30"],
			["empEmployee.employeeOrder","人员排序","int","20"],
			["empEmployee.nation","民族","max","String:30"],
			["empEmployee.politicsStatus","政治面貌","max","String:30"],
			["empEmployee.mobileTelephone","移动电话","max","String:20"],
			["empEmployee.email","电子邮箱","email",""],
			["empEmployee.email","电子邮箱","max","String:50"],
			["empEmployee.areaId","地区","notEmpty",""],
			["empEmployee.areaDeptId","事业部","notEmpty",""],
			["empEmployee.saleDeptId","销售分线","notEmpty",""],
			["empEmployee.createDate","录入日期","notEmpty",""],
			["empEmployee.empRemark","备注","max","String:1000"]
			
			
		);
		if(xj.CheckAll(objarr))
		{
			if(confirm("确认保存？"))
			{
				document.getElementById("employeeForm").submit();
			}
		}
	}
	function checkIdNumber(){
	
			var sfz = $("input[name='empEmployee.idNumber']").val();
          	var yy,mm,dd,csrq,age,sex,xingbie,xbtext;
			//********************************************身份证为15位
			if (sfz.length==15 )
			{
				yy=sfz.substr(6,2);
				mm=sfz.substr(8,2);
				dd=sfz.substr(10,2);
				csrq=yy+"-"+mm+"-"+dd;
				$("input[name='empEmployee.employeeBirthday']").val(csrq);
				xingbie=sfz.substr(14,1);
				
				if(xingbie%2==0)
					xbtext='女';
				else
					xbtext='男';
				
				$("#employeeGender").val(xbtext);

			}
			
			//********************************************身份证为18位
			if (sfz.length==18 )
			{
				yy=sfz.substr(6,4);
				mm=sfz.substr(10,2);
				dd=sfz.substr(12,2);
				csrq=yy+"-"+mm+"-"+dd;
				$("input[name='empEmployee.employeeBirthday']").val(csrq);
				xingbie=sfz.substr(16,1);
				if(xingbie%2==0)
					xbtext='女';
				else
					xbtext='男';
				$("#employeeGender").val(xbtext);

				
			}
			return "";
     }        

	//返回
	function goback()
	{
		window.location.href="listEmployee.do";
	}

	function getSuggectCode()
	{
		var tmp = parseInt(Math.random()*10000+1);//设定随机数防止浏览器以相同url重复多次访问不进行请求
		var url = 'getSuggestCodeEmployee.do?employeeName='+$("#employeeName").val()+"&tmp="+tmp;
		$.get(encodeURI(url), {},function (data, textStatus){
			$("#suggestCode").val(data);
		});
	}
	var codeState = true;
	function checkEmployeeCode()
	{
		xj.replaceAllNoticeDiv();
		
		var tmp = parseInt(Math.random()*10000+1);//设定随机数防止浏览器以相同url重复多次访问不进行请求
		var url = 'checkExistsEmployee.do?employeeCode='+$("#employeeCode").val()+"&tmp="+tmp;
		$.get(url, {},function (data, textStatus){
			if(data=="exists")
			{
				xj.showNoticeDiv(document.getElementById("employeeCode"),"员工代码已存在，请更换！",false);
				codeState = false;
			}
			else
			{
				codeState = true;
				xj.replaceAllNoticeDiv();
			}
		});
	}
	function selectOption(objSelect,hiddenId)
	{
		$("#"+hiddenId).val($(objSelect).find("option:selected").text());
	}
</script>

</head>
<body>
<form name="form1" id="employeeForm"  action="addEmployee.do" method="post" enctype="multipart/form-data">
	<div id="body_div">
	<w:ShowTitle name="添加员工">
	<w:TitleButton funcName="保存" onClickFunction="saveData()" urlImg="${ctx}/images/main/save.png" />
	<w:TitleButton funcName="返回" onClickFunction="goback()" urlImg="${ctx}/images/main/back.png"/>
	</w:ShowTitle>
	<div id="body_content">
	<table width="100%" id="content0" class="tabContent">
            <tr>
              <td width="90" class="right_align">姓名</td>
              <td width="170" class="left_align"><input type="text" name="empEmployee.employeeName" id="employeeName" onblur="getSuggectCode()"/></td>
              <td width="120" class="right_align">员工编号</td>
              <td width="170" class="left_align"><input type="text" name="empEmployee.employeeCode" id="employeeCode" value="${employeeCode}" onblur="checkEmployeeCode()"/></td>
              <td width="90" class="right_align">性别</td>
              <td width="150" class="left_align">
				<w:select name="empEmployee.employeeGender" onclick="return false;" styleId="employeeGender">
					<w:option optionLabel="男" optionValue="男"></w:option>
					<w:option optionLabel="女" optionValue="女"></w:option>
				</w:select>
              </td>
              <td width="120" class="right_align">出生日期</td>
              <td class="left_align">
              <input type="text" name="empEmployee.employeeBirthday" onfocus="new WdatePicker()" readonly="readonly" class="inputCal"/>
              </td>
            </tr>
            <tr>
              <td class="right_align">地区</td>
              <td class="left_align">
              	<input type="hidden" id="areaName" name="empEmployee.areaName"/>
              	<w:select name="empEmployee.areaId" value="${empEmployee.areaId}" onchange="selectOption(this,'areaName')">
					<w:option optionLabel="请选择" optionValue=""></w:option>
					<w:options options="${CodeDict}" optionLabel="codeName" optionValue="codeId" filterFieldName="parentCodeId" filterFieldValue="001"></w:options>
				</w:select>
              </td>
              <td class="right_align">事业部</td>
              <td class="left_align">
              	<input type="hidden" id="areaDeptName" name="empEmployee.areaDeptName"/>
              	<w:select name="empEmployee.areaDeptId" value="${empEmployee.areaDeptId}" onchange="selectOption(this,'areaDeptName')">
					<w:option optionLabel="请选择" optionValue=""></w:option>
					<w:options options="${CodeDict}" optionLabel="codeName" optionValue="codeId" filterFieldName="parentCodeId" filterFieldValue="002"></w:options>
				</w:select>
              </td>
              <td class="right_align">销售分线</td>
              <td class="left_align">
              	<input type="hidden" id="saleDeptName" name="empEmployee.saleDeptName"/>
              	<w:select name="empEmployee.saleDeptId" value="${empEmployee.saleDeptId}" onchange="selectOption(this,'saleDeptName')">
					<w:option optionLabel="请选择" optionValue=""></w:option>
					<w:options options="${CodeDict}" optionLabel="codeName" optionValue="codeId" filterFieldName="parentCodeId" filterFieldValue="003"></w:options>
				</w:select>
              </td>
              <td class="right_align">在岗情况</td>
              <td class="left_align">
              	<w:select name="empEmployee.onJobSituation">
              		<w:option optionLabel="在岗" optionValue="在岗"></w:option>
              		<w:option optionLabel="离岗" optionValue="离岗"></w:option>
				</w:select>
              </td>
            </tr>
            <tr>
              <td class="right_align">身份证号</td>
              <td class="left_align"><input type="text" name="empEmployee.idNumber" onblur="checkIdNumber()"/></td>
              <td class="right_align">政治面貌</td>
              <td class="left_align">
              	<input type="text" name="empEmployee.politicsStatus"/>
              </td>
              <td class="right_align">民族</td>
              <td class="left_align">
              	<input type="text" name="empEmployee.nation"/>
              </td>
              <td class="right_align">移动电话</td>
              <td class="left_align"><input type="text" name="empEmployee.mobileTelephone"/></td>
            </tr>
            <tr>
              <td class="right_align">电子邮箱</td>
              <td class="left_align"><input type="text" name="empEmployee.email"/></td>
              <td class="right_align">录入日期</td>
              <td class="left_align"><input type="text" name="empEmployee.createDate" value="${wfn:getDateTime("yyyy-MM-dd")}" onfocus="new WdatePicker()" readonly="readonly" class="inputCal"/></td>
              <td class="right_align">人员排序</td>
              <td class="left_align"><input type="text" name="empEmployee.employeeOrder"/></td>
              <td class="right_align"></td>
              <td class="left_align"><input type="hidden" name="empEmployee.suggestCode" id="suggestCode"/></td>
            </tr>
            <tr>
              <td class="right_align">备注</td>
              <td colspan="8" class="left_align">
              	<textarea rows="5" cols="80" name="empEmployee.empRemark"></textarea>
              </td>
            </tr>
          </table>
	</div>
	</div>	
</form>
</body>
</html> 